{php include wl_template('common/header');}
<style type='text/css'>
	.trbody td{text-align: center;vertical-align:top;border-left:1px solid #ccc;border-bottom: 1px solid #ddd;}
	.order-rank img{width:16px;height:16px;}
	.js-remark,.js-admin-remark{word-break:break-all;overflow:hidden;background: #FDEEEE;color: #ED5050;padding: 5px 10px;}
	td.goods-info{position:relative;padding-left:60px;}
	.goods-info .img{position:absolute;top:50%;margin-top:-25px;background: url({IMAGE_LOADING}
	) center center no-repeat;width:50px;height:50px;}
	.goods-info span{white-space: inherit;overflow: hidden;text-overflow: ellipsis;display: block;}
	.status-text{cursor:pointer;}
	.table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td{border-top: 1px solid rgba(221, 221, 221, 0);}
	.col-md-1{padding-right: 0px;}
	.all-tips{margin-left: 65px;}
	span.effect-time{font-size: 12px;display: block;font-weight: 500;}
	.row.row-fix, .form-group.form-group-fix{margin-left: -15px;margin-right: -15px;width: 500px;}
	button.btn.btn-default.daterange.daterange-date{float: left;margin-left: 234px;position: absolute;z-index: 100;}
	#sel_child{z-index: 10;width: 200px;position: absolute;display: none;}
	.show1{display: block;}
	.hide1{display: none;}
	.daterange-date{display: none;}
	.sty{display: block;width: 100%;font-size: 13px;height: 46px;overflow: hidden;white-space: nowrap;line-height: 46px;text-overflow: ellipsis;text-align: center;}
	.spe{display: inline-block;text-align: center;display: block;height: 33px;margin-left: -12px;padding-top: 0px;line-height: 33px;}
	.table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td{white-space: normal;}
	span.ppp{text-align: center;display: inline-block;font-size: 14px;width: 100%;overflow: hidden;text-overflow: ellipsis;color: #e43;}
	select#sel_parent{z-index: 1000;}
	.nickname{margin-left: 94px;height: 34px;width: 200px;}
	.col-xs-12.col-sm-6.col-sm-9.col-lg-6{z-index: 9999;}
	.start-time{font-size: 12px;}
	.end-time{font-size: 12px;}
	.mouth{margin-left: 94px;height: 34px;width:130px;display: none;}
</style>
<ul class="nav nav-tabs" id="myTab">
	<li class="active"><a href="#">商家特权</a></li>
</ul>
<div class="app-content">
	<div class="app-filter">
		<div class="filter-action"><a href="{php echo web_url('halfcard/halfcard_web/createHalfcard');}" class="btn btn-primary">添加特权</a></div>
		<div class="filter-list">
			<form action="" method="get" class="form-horizontal" role="form" id="form1">
				<input type="hidden" name="c" value="site" />
				<input type="hidden" name="a" value="entry" />
				<input type="hidden" name="m" value="{MODULE_NAME}" />
				<input type="hidden" name="p" value="halfcard" />
				<input type="hidden" name="ac" value="halfcard_web" />
				<input type="hidden" name="do" value="halfcardList" />
				<input type="hidden" name="status" value="{$_GPC['status']}" />
				<input type="hidden" name="daily" value="{$_GPC['daily']}" />
				<div class="form-group">
					<label class="col-sm-2 control-label">特权状态</label>
					<div class="col-sm-9">
						<div class="btn-group">
							<a href="{php echo wl_filter_url('status:0');}" class="btn {if intval($_GPC['status']) == 0}btn-primary{else}btn-default{/if}">不限</a>
							<a href="{php echo wl_filter_url('status:1');}" class="btn {if $_GPC['status'] == 1}btn-primary{else}btn-default{/if}">启用中</a>
							<a href="{php echo wl_filter_url('status:4');}" class="btn {if $_GPC['status'] == 4}btn-primary{else}btn-default{/if}">未启用</a>
							<a href="{php echo wl_filter_url('status:2');}" class="btn {if $_GPC['status'] == 2}btn-primary{else}btn-default{/if}">审核中</a>
							<a href="{php echo wl_filter_url('status:3');}" class="btn {if $_GPC['status'] == 3}btn-primary{else}btn-default{/if}">被驳回</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">平时折扣</label>
					<div class="col-sm-9">
						<div class="btn-group">
							<a href="{php echo wl_filter_url('daily:0');}" class="btn {if intval($_GPC['daily']) == 0}btn-primary{else}btn-default{/if}">不限</a>
							<a href="{php echo wl_filter_url('daily:1');}" class="btn {if $_GPC['daily'] == 1}btn-primary{else}btn-default{/if}">有</a>
							<a href="{php echo wl_filter_url('daily:2');}" class="btn {if $_GPC['daily'] == 2}btn-primary{else}btn-default{/if}">无</a>
						</div>
					</div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label">关键字</label>
					<div class="col-md-3">
						<select name="keywordtype" class="form-control">
							<option value="">关键字类型</option>
							<option value="2" {if $_GPC['keywordtype']==2}selected="selected"{/if}>特权标题</option>
							<option value="1" {if $_GPC['keywordtype']==1}selected="selected"{/if}>按星期</option>
							<option value="3" {if $_GPC['keywordtype']==3}selected="selected"{/if}>按月天数</option>
						</select>
                    </div>
                    <div class="col-md-4">
                        <input type="text" name="keyword" class="form-control" value="{$_GPC['keyword']}"  placeholder="请输入关键字"/>
                    </div>
				</div>
				<div class="form-group">
					<label class="col-sm-2 control-label"></label>
					<div class="col-sm-9">
						<button class="btn btn-primary" id="search">筛选</button>
					</div>
				</div>
			</form>
		</div>
	</div>
	<div class="app-table-list">
		<div class="order-list">
			<div class="panel-body table-responsive collapse in" id="order-template-item-4" style="padding: 0;">
				<table class="table table-bordered">
					<thead style="background-color: #FFFFFF;">
					<tr>
						<th style="width:40px">序号</th>
						<th style="width:190px;text-align:center;">特权标题</th>
						<th style="width:150px;text-align:center;">所属商家</th>
						<th style="width:180px; text-align:center;">使用限制说明</th>
						<th style="width:60px; text-align: center;">特权折扣</th>
						<th style="width:120px; text-align: center;">活动时间</th>
						<th style="width:60px; text-align: center;">平时折扣</th>
						<th style="width:90px; text-align: center;">状态</th>
						<th style="width:90px; text-align: center;">操作</th>
					</tr>
					</thead>
					<tbody>
					{loop $halfcard $y $item}
						<tr>
							<td style="width: 40px;" ><center>{php echo $y+1}</center></td>
							<td class="goods-info line-feed" style="width:190px;padding-left: 10px;">
								<div class="img"><img src="{IMAGE_PIXEL}" class="scrollLoading" data-url="{php echo tomedia($item['logo'])}" height="50" width="50" ></div>
								<div class="all-tips">
									<span class="" style="font-family: "Arial","Microsoft YaHei","黑体","宋体",sans-serif ;">{$item['title']}</span>
								</div>
							</td>
							<td class="text-center" style="width:150px;height:60px;font-family: "Arial","Microsoft YaHei","黑体","宋体",sans-serif ;">
							<p>{$item['storename']}</p>
							</td>
							<td class="text-center" style="width:180px;height:60px;font-family: "Arial","Microsoft YaHei","黑体","宋体",sans-serif ;">
							<p>{$item['limit']}</p>
							</td>
							<td class="text-center" style="width:60px;">
								<span  class="label label-default">{if $item['datestatus'] !=3 } {$item['activediscount']}折 {else}无{/if}</span>
							</td>
							<td class="text-center" style="width: 120px; font-size: 12px;" id="td1">
								{if $item['datestatus'] == 1}
								{loop $item['week'] $week}
								{if $week==1}<span>星期一</span>,{/if}
								{if $week==2}<span>星期二</span>,{/if}
								{if $week==3}<span>星期三</span>,{/if}
								{if $week==4}<span>星期四</span>,{/if}
								{if $week==5}<span>星期五</span>,{/if}
								{if $week==6}<span>星期六</span>,{/if}
								{if $week==7}<span>星期日</span>{/if}
								{/loop}
								{else if $item['datestatus'] == 2}
								{loop $item['day'] $day}
								<span>{$day}号,</span>
								{/loop}
								{else}
								<span  class="label label-default">无特权折扣</span>
								{/if}
							</td>
							<td class="text-center" style="width:60px;">
								{if $item['daily']==1}<span  class="label label-success">{$item['discount']}折</span>{/if}
								{if $item['daily']==0}<span  class="label label-danger">无折扣</span>{/if}
							</td>
							<td class="text-center" id="text-click" order-id="{$item['id']}" order-status="{$item['status']}" style="width:90px;">
								<a>
									{if $item['status']==1}<span  class="label label-success">已启用</span>{/if}
									{if $item['status']==0}<span  class="label label-default">已禁用</span>{/if}
									{if $item['status']==2}<span  class="label label-warning">审核中</span>{/if}
									{if $item['status']==3}<span  class="label label-danger">已驳回</span>{/if}
								</a>
							</td>
							<td class="text-center">
								<a href="{php echo web_url('halfcard/halfcard_web/userhalfcardlist', array('id' => $item['id'],'title'=>$item['title']))}" >使用记录 -</a>
								{if $item['status'] == 2 || $item['status'] == 3}
								<a href="javascript:;" class="js-pass" order-id="{$item['id']}" > 通过 -</a>
								{/if}
								{if $item['status'] == 2}
								<a href="javascript:;" class="js-reject" order-id="{$item['id']}" > 驳回 -</a>
								{/if}
								<a href="{php echo web_url('halfcard/halfcard_web/editHalfcard', array('id' => $item['id']))}" class="js-edit" order-id="{$item['id']}"> 编辑 -</a>
								<a href="javascript:;" class="js-remove" order-id="{$item['id']}" >删除</a>
							</td>
						</tr>
					{/loop}
					</tbody>
				</table>
			</div>
		</div>
		<div class="app-table-foot clearfix">
			<div class="pull-left">

			</div>
			<div class="pull-right">
				{$pager}
			</div>
		</div>
	</div>
</div>
<script type="text/javascript">
	$("#search").click(function(){
		$('#form1')[0].submit();
	});
</script>
<script type="text/javascript">
	require(['jquery', 'util'], function($, util){
		$('.js-copy').each(function(){
			var id=$(this).attr('data-id');
			util.clip($("#js-copy"+id), $(this).attr('data-url'));
		});
	});
</script>
<script type="text/javascript">
	$('.panel-default').delegate('#text-click', 'click', function(e){

		e.stopPropagation();
		var $this = $(this);
		var id = $this.attr('order-id');
		var status = $this.attr('order-status');
		var statushtml = (status != 0) ? "已禁用" : "已启动";
			$.post("{php echo web_url('halfcard/halfcard_web/delete')}", {id:id,status:status}, function(data){
				console.log(data);
				if(!data.errno){
					util.tips(statushtml+"成功！");
					location.reload();
				};
			}, 'json');
	});
	$('#output').click(function(){
		var orderType = '{$_GPC['orderType']}';
		var status = '{$_GPC['status']}';
		var paytype = '{$_GPC['pay_type']}';
		var keywordtype = '{$_GPC['keywordtype']}';
		var keyword = '{$_GPC['keyword']}';
		var timetype = '{$_GPC['timetype']}';
		var times = "{$_GPC['time']['start']}";
		var timee = "{$_GPC['time']['end']}";
		location.href = "{php echo web_url('halfcard/order/output')}&orderType="+orderType+"&status="+status+"&paytype="+paytype+"&keywordtype="+keywordtype+"&keyword="+keyword+"&timetype="+timetype+"&times="+times+"&timee="+timee;
	});
	$(function(){
		{if ($flag1 || $daily)}
			$('#sel_child').show();
			$('#box2').hide();
		{/if}
		$('[name="rank_all"]').click(function() {
			var checked = this.checked;
			$('.js-rank').find('input:checkbox').each(function() {
				this.checked = checked;
			});
		});
		$('#export').click(function() {
			if ($('[name="selecttime[start]"]').val() == '') {
				alert('请选择下单时间');
				$(this).focus();
				return false;
			};
			$(this).attr('type', 'submit').submit();
		});

		$('.order-rank').each(function(){
			o.rank(this);
		});

		//删除
		$('.order-list').delegate('.js-remove', 'click', function(e){
			e.stopPropagation();
			var $this = $(this);
			var id = $this.attr('order-id');
			tip.confirm("此操作会删除特权活动，同时导致订单商品数据缺失或其他问题，确定要删除吗？",function () {
					$.post("{php echo web_url('halfcard/halfcard_web/deleteHalfcard')}", {id: id}, function (data) {
						if (!data.errno) {
							$this.parent().parent().parent().remove();
							util.tips("删除成功！");
						}

								;
					}, 'json');
			});
		});

		$('.order-list').delegate('.js-pass', 'click', function(e){
			e.stopPropagation();
			var $this = $(this);
			var id = $this.attr('order-id');
			var flag = 1;
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('halfcard/halfcard_web/passHalfcard')}", { id : id , flag : flag, type : 1}, function(data){
					if(!data.errno){
					util.tips("通过成功！");
        			location.reload();
					};
				}, 'json');
			}, {html: '通过审核?'});
		});
		$('.order-list').delegate('.js-reject', 'click', function(e){
			e.stopPropagation();
			var $this = $(this);
			var id = $this.attr('order-id');
			var flag = 0;
			util.nailConfirm(this, function(state) {
				if(!state) return;
				$.post("{php echo web_url('halfcard/halfcard_web/passHalfcard')}", { id : id , flag : flag, type : 1 }, function(data){
					if(!data.errno){
					util.tips("驳回成功！");
        			location.reload();
					};
				}, 'json');
			}, {html: '确认驳回?'});
		});

		$('#de1').delegate('.js-delete','click',function(e){
			e.stopPropagation();
			var order_ids = [];
			var $checks=$('.checkbox:checkbox:checked');
			$checks.each(function() {
				if (this.checked) {
					order_ids.push(this.value);
				};
			});
				var $this = $(this);
				var ids = order_ids;
			//	alert(ids);
				util.nailConfirm(this, function(state) {
				if(!state) return;
					$.post("{php echo web_url('halfcard/halfcard_web/deleteHalfcard')}", { ids : ids }, function(data){
						if(!data.errno){
						util.tips("删除成功！");
						location.reload();
						};
					}, 'json');
				}, {html: '确认删除?'});
			});
		});
$('#sel_parent').click(function(){
	if(this.value != 1 && this.value != 4){
		$('.daterange-date').hide();
		$('#sel_child').hide();
		$(".nickname").removeAttr("style");
		$('.nickname').show();
		$('.mouth').hide;
		$('.mouth').removeAttr('style');
	}
	else{
		$('.daterange-date').hide();
		$('.nickname').hide();
		$('#sel_child').show();
		$('#sel_child').attr("display","block");
		$('.mouth').hide();
	}
//alert(this.value);
	if(this.value==0){
		$('#sel_child').hide();
		$('.mouth').hide;
	}
	if(this.value==3){
		$('#sel_child').hide();
		$('.mouth').show();
	}
});



</script>
{php include wl_template('common/footer');}